<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            // 解构赋值数组
            let arr = [1, 2];

            let [x, y] = arr;

            console.log(x, y);

            // 利用解构赋值交换值
            let a = 3;
            let b = 4;

            [a,b] = [b,a]
            console.log(a,b);


            // 解构赋值对象
            // 和数组相比 不需要对照index  对象根据key去解构
            let obj = {
                name:'a',
                age:22 ,
                sex:'b'
            }
            let {age , name} = obj
            console.log(name , age);

            // 给定默认值 
            let [ [i = 9] , p , q] = [[ 30 ] , 10 ,100] 
            console.log(i , p ,q);


            

        </script>
    </body>
</html>
